package com.huawei;
import java.util.*;
/**
 * Created by Z-hong on 2024/7/18.
 */

public class HJ43 {

    public static List<Point> res = new ArrayList<>();
    public static class Point{
        int x;
        int y;
        public Point(int x,int y) {
            this.x=x;
            this.y=y;
        }
        @Override
        public String toString(){
            return "("+x+","+y+")";
        }
    }

    public static class Flag{
        int [][] arr;
        List<Point> list;

        public Flag(int[][] arr,List<Point> list) {
            this.arr=deepClone(arr);
            this.list=list;
        }

        public int[][] deepClone(int[][] original){
            if(original==null){return null;}
            int[][] result = new int[original.length][];
            for (int i = 0; i < original.length; i++) {
                result[i] = original[i].clone();
            }
            return result;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m=sc.nextInt();
        int [][] arr=new int[n][m];
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[0].length; j++) {
                arr[i][j]=sc.nextInt();
            }
        }
        List<Point> points=new ArrayList<>();
        points.add(new Point(0,0));
        arr[0][0]=1;
        dfs(0,0,new Flag(arr,points));

        for (Point re : res) {
            System.out.println(re.toString());
        }

    }

    public static boolean dfs(int i,int j,Flag flag){
        int [][]arr=flag.arr;
        if(i==arr.length-1&&j==arr[0].length-1){
            res.addAll(flag.list);
            return true;
        }
        if(i+1<arr.length&&arr[i+1][j]!=1){
            arr[i+1][j]=1;
            List<Point> points=new ArrayList<>(flag.list);
            points.add(new Point(i+1,j));
            boolean dfs = dfs(i + 1, j, new Flag(arr, points));
            if(dfs) return true;
            arr[i+1][j]=0;
        }
        if(i-1>=0&&arr[i-1][j]!=1){
            
            arr[i-1][j]=1;
            List<Point> points=new ArrayList<>(flag.list);
            points.add(new Point(i-1,j));
            boolean dfs = dfs(i - 1, j, new Flag(arr, points));
            if(dfs) return true;
            arr[i-1][j]=0;
        }
        if(j-1>=0&&arr[i][j-1]!=1){

            arr[i][j-1]=1;
            List<Point> points=new ArrayList<>(flag.list);
            points.add(new Point(i,j-1));
            boolean dfs = dfs(i , j-1, new Flag(arr, points));
            if(dfs) return true;
            arr[i][j-1]=0;

        }
        if(j+1<arr[0].length&&arr[i][j+1]!=1){
            arr[i][j+1]=1;
            List<Point> points=new ArrayList<>(flag.list);
            points.add(new Point(i,j+1));
            boolean dfs = dfs(i , j+1, new Flag(arr, points));
            if(dfs) return true;
            arr[i][j+1]=0;
        }

        return false;
    }
}
